package com.starblink.home.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.starblink.home.R;
import com.starblink.rocketreserver.fragment.SearchWordVOF;

import java.util.ArrayList;
import java.util.List;

/**
 * @author dyhpc
 */
public class HotWordFlipperAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<SearchWordVOF> data;

    public HotWordFlipperAdapter(Context context, ArrayList<SearchWordVOF> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data == null ? 0 : data.size();
    }

    @Override
    public Object getItem(int position) {
        return data == null ? null : data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder viewHolder;
        if (convertView == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_home_flipper_text, parent, false);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            view = convertView;
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tv_item.setText(data.get(position).getShowWord());
        return view;
    }

    static class ViewHolder {
        public TextView tv_item;

        public ViewHolder(View view) {
            this.tv_item = view.findViewById(R.id.tv_item);
        }
    }
}
